﻿using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Text;

namespace SXFramWork.Core.Extension
{
    public static class HttpRequestExtension
    {
        /// <summary>
        /// 获取根地址
        /// </summary>
        /// <param name="request"></param>
        /// <param name="path">附加路径</param>
        /// <returns></returns>
        public static string GetHost(this HttpRequest request, string path = null)
        {
            return request.Scheme + "://" + request.Host.Value + (path ?? string.Empty);
        }
        public static string GetAbsoluteUri(this HttpRequest request)
        {
            return new StringBuilder()
             .Append(request.Scheme)
             .Append("://")
             .Append(request.Host)
            // .Append(request.PathBase)
            // .Append(request.Path)
            // .Append(request.QueryString)
             .ToString();
        }
    }
}
